// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

function get_time_flag(datetime) {
  let vars = []
  let result = '';
  vars = datetime.split('-');
  let n1 = parseInt(vars[0]);
  let n2 = parseInt(vars[1]);
  if (n1 < 13 && n2 <= 13) {
    result = '上午';
    this.setData({
      cur_css: 'swdayView'
    })
  } else if (n1 >= 13 && (n2 >= 13 && n2 <= 19)) {
    result = '下午'
    this.setData({
      cur_css: 'xwdayView'
    })
  }
  else if (n1 < 11 && n2 > 13) {
    result = '全天'
    this.setData({
      cur_css: 'onedayView'
    })
  }
  return result
}

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  
  return {
    event,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
    get_time_flag: get_time_flag,
  }
}